import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:like_button/like_button.dart';
import 'package:live_music/models/moment_detail_model.dart';
import 'package:live_music/utils/colors.dart';

class VideoRightBarWidget extends StatefulWidget {
  final Function onClickComment;
  final Function onClickShare;
  final Function onClickHeader;
  final MomentDetailModel videoItem;
  final Function onAddFavorite;
  final Function onCollect;
  final Function onFollowed;
  // FeedListList video;
  VideoRightBarWidget(
      {Key key,
      this.onClickComment,
      this.onClickShare,
      this.videoItem,
      this.onClickHeader,
      this.onAddFavorite,
      this.onCollect,
      this.onFollowed})
      : super(key: key);

  @override
  _VideoRightBarWidgetState createState() {
    return _VideoRightBarWidgetState();
  }
}

class _VideoRightBarWidgetState extends State<VideoRightBarWidget> {
  double _widgetWidth = 50;
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return ConstrainedBox(
      constraints: BoxConstraints(
        maxWidth: _widgetWidth,
      ),
      child: Column(
        children: [
          _getHeader(),
          SizedBox(
            height: 25,
          ),
          _getLikeButton(),
          SizedBox(
            height: 15,
          ),
          _getCommentButton(),
          SizedBox(
            height: 15,
          ),
          //获取收藏按钮
          _getCollectButton(),
          SizedBox(
            height: 15,
          ),
          _getShareButton(),
        ],
      ),
    );
  }

  //头像
  _getHeader() {
    return InkWell(
      onTap: () {
        widget.onClickHeader?.call();
      },
      child: Container(
        width: _widgetWidth,
        height: _widgetWidth + _widgetWidth / 8 * 3 / 2,
        child: Stack(
          alignment: Alignment.bottomCenter,
          children: [
            Container(
              margin: EdgeInsets.only(bottom: _widgetWidth / 8 * 3 / 2),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(_widgetWidth / 2),
                  border: Border.fromBorderSide(
                      BorderSide(color: Colors.white, width: 2)),
                  image: DecorationImage(
                      image: widget.videoItem.userAvatarUrl == null
                          ? AssetImage('assets/images/person_holder.png')
                          : NetworkImage(widget.videoItem.userAvatarUrl),
                      fit: BoxFit.cover)),
            ),
            !widget.videoItem.hasFollowed
                ? Positioned(
                        child: InkWell(
                    onTap: () {
                      widget.onFollowed?.call(!widget.videoItem.hasFollowed);
                    },
                    child: Container(
                            width: 20,
                            height:20,
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(
                                 10),
                              color: ColorRes.color_3,
                            ),
                            child: Icon(
                              Icons.add,
                              color: Colors.white,
                              size: 15,
                            ))),
                  )
                : SizedBox(
                    width: 0,
                    height: 0,
                  ),
          ],
        ),
      ),
    );
  }

  Future<bool> onTapLikeButton(bool isLiked) async {
    widget.onAddFavorite?.call(!isLiked);
    return !isLiked;
  }

  Future<bool> onTapCollectButton(bool isLiked) async {
    widget.onCollect?.call(!isLiked);
    return !isLiked;
  }

  //获取收藏按钮
  _getCollectButton() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        LikeButton(
            onTap: (isLiked) {
              return onTapCollectButton(isLiked);
            },
            isLiked: widget.videoItem.video.hasCollected,
            size: 40,
            circleColor:
                CircleColor(start: ColorRes.color_4, end: ColorRes.color_4),
            likeBuilder: (isLike) {
              return isLike == true
                  ? Image.asset('assets/images/icons/has_collect.png')
                  : Image.asset(
                      'assets/images/icons/has_no_collect.png',
                      color: Colors.white,
                    );
            },
            bubblesColor: const BubblesColor(
              dotPrimaryColor: ColorRes.color_4,
              dotSecondaryColor: ColorRes.color_4,
              dotThirdColor: ColorRes.color_4,
              dotLastColor: ColorRes.color_4,
            )),
        SizedBox(
          height: 2,
        ),
        Text(
          widget.videoItem.video.collectCount.toString(),
          style: TextStyle(color: Colors.white),
        )
      ],
    );
  }

  //获取点赞按钮
  _getLikeButton() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        LikeButton(
            onTap: (isLiked) {
              return onTapLikeButton(isLiked);
            },
            isLiked: widget.videoItem.hasLiked,
            size: 40,
            circleColor:
                CircleColor(start: ColorRes.color_3, end: ColorRes.color_3),
            likeBuilder: (isLike) {
              return isLike == true
                  ? Image.asset('assets/images/common/red_heart.webp')
                  : Image.asset(
                      'assets/images/common/red_heart.webp',
                      color: Colors.white,
                    );
            },
            bubblesColor: const BubblesColor(
              dotPrimaryColor: ColorRes.color_3,
              dotSecondaryColor: ColorRes.color_3,
              dotThirdColor: ColorRes.color_3,
              dotLastColor: ColorRes.color_3,
            )),
        SizedBox(
          height: 2,
        ),
        Text(
          widget.videoItem.likeCount.toString(),
          style: TextStyle(color: Colors.white),
        )
      ],
    );
  }

  //获取评论按钮
  _getCommentButton() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        IconButton(
          iconSize: _widgetWidth,
          padding: const EdgeInsets.all(0.0),
          onPressed: () {
            widget.onClickComment?.call();
          },
          icon: Image.asset(
            'assets/images/common/comment.webp',
          ),
        ),
        Text(
          widget.videoItem.commentCount.toString(),
          style: TextStyle(color: Colors.white),
        )
      ],
    );
  }

  //获取分享按钮
  _getShareButton() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        IconButton(
          iconSize: _widgetWidth,
          padding: const EdgeInsets.all(0.0),
          onPressed: () {
            widget.onClickShare?.call();
          },
          icon: Image.asset(
            'assets/images/common/share_button.webp',
            width: 35,
            height: 35,
          ),
        ),
        Text(
          widget.videoItem.shareCount.toString(),
          style: TextStyle(color: Colors.white),
        )
      ],
    );
  }
}
